package ycl.message.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import ycl.common.ApiResult;
import ycl.common.models.base.A;
import ycl.common.models.req.SmsReq;
import ycl.common.models.req.base.SendEmailReq;
import ycl.message.service.MessageService;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 消息控制器
 *
 * @author ycl
 * @date 2022/6/16 0016 11:17:20
 */
@Slf4j
@RestController
@RequestMapping("/email")
@Api(tags = "邮箱")
public class EmailController {

	@Resource
	private MessageService messageService;

	@GetMapping("clearGetEmailCount")
	@ApiOperation("定时器自动调用: 删除用户日获取邮件的次数")
	@ApiOperationSupport(order = 1111)
	@ApiIgnore
	public ApiResult<A> clearGetEmailCount(){
		log.info("come in clearGetEmailCount --- ");
		messageService.deleteSendCount();
		return ApiResult.success();
	}

	@PostMapping("send")
	@ApiOperation("发送邮件")
	@ApiOperationSupport(order = 1)
	@ApiIgnore
	public ApiResult<A> send(@RequestBody @Valid SendEmailReq req) {
		return messageService.sendEmail(req);
	}


	@PostMapping("sendAuthCodeBindMobile")
	@ApiOperation("绑定手机发送验证码(暂时先发到邮箱上)")
	@ApiOperationSupport(order = 1)
	public ApiResult<A> sendAuthCodeBindMobile(@RequestBody @Valid SmsReq req){
		return messageService.sendAuthCodeBindMobile(req);
	}


}
